package com.ehotting.edsta.simulation.controller;

import com.ehotting.eaf.core.web.controller.BaseController;
import com.ehotting.eaf.core.web.domain.AjaxResult;
import com.ehotting.eaf.redis.service.RedisService;
import com.ehotting.eaf.security.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.Session;
import java.io.IOException;

@Api(tags = "TestController",description = "多物理场仿真求解器服务测试接口")
@RestController
@RequestMapping("/simulation")
public class TestController extends BaseController {

    @Autowired
    private RedisService redisService;

    @Autowired
    private TokenService tokenService;

    @ApiOperation("多物理场仿真求解器服务测试接口")
    @GetMapping("/test")
    public AjaxResult test(){
        return AjaxResult.success("simulation test success");
    }

    @GetMapping("/testWs")
    public void testWs() throws IOException {
        Session session = redisService.getCacheObject(tokenService.getLoginUser().getUserid() + "");
        if (session!=null){
            session.getBasicRemote().sendText("test success");
        }
    }
}
